/****************************************************
          File Name:17-4.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon Jan 19 18:07:04 2015
*****************************************************/

#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;

int main(int argc, char *argv[])
{
    if(argc < 4)
    {
        cerr << argv[0] << "src1 src2 dst (filename)" << endl;
       exit(EXIT_FAILURE); 
    }

    ifstream if1, if2;
    ofstream of;
    string str1, str2;
    bool err1 = false;
    bool err2 = false;

    try
    {
        if1.open(argv[1]);
        if2.open(argv[2]);
    }
    catch(ios_base::failure bad)
    {
        cerr << bad.what() << endl;
    }

    of.open(argv[3], ios_base::out);

    while(1)
    {
        if(!getline(if1, str1))
        {
            str1 = "";
            err1 = true;
        }
        if(!getline(if2, str2))
        {
            str2 = "";
            err2 = true;
        }
        of << str1 << " " << str2 << endl;
        if(err1 && err2)
            break;
    }

    if1.close();
    if2.close();
    of.close();
    return 0;
}
